package hlhj.fhp.checkpoint.atys

import android.os.Build
import android.support.annotation.RequiresApi
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewTreeObserver
import com.example.mymvp.log
import com.example.mymvp.mvp.BaseModule
import com.example.mymvp.mvp.BasePresenter
import com.example.mymvp.mvp.BaseView
import com.huantansheng.easyphotos.models.puzzle.Line
import com.liaoinstan.springview.utils.DensityUtil
import hlhj.fhp.checkpoint.BaseAty
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.adp.TestAdp
import kotlinx.android.synthetic.main.aty_test.*

/**
 * Created by Never Fear   on 2018\12\5 0005.
Never More....
 */
class TestAty :BaseAty<BaseView,BasePresenter<*,BaseView>>(), BaseView {
    private var testAdp:TestAdp?=null
    private val datas=ArrayList<String>()
    private var linearLayoutManager: LinearLayoutManager?=null
        get() {
            val linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
            return linearLayoutManager
        }

    override fun initView() {
        for (i in 0..50){
            datas.add("1")
        }
        testAdp= TestAdp(datas)
        listView.adapter=testAdp
        linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        listView?.layoutManager= linearLayoutManager
    }

    override fun logicStart() {
    }

    @RequiresApi(Build.VERSION_CODES.M)
    override fun setListener() {
        listView.addOnScrollListener(object :RecyclerView.OnScrollListener(){
            override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) {
                super.onScrollStateChanged(recyclerView, newState)
                log("fhp","新的状态问${newState}")
                if (newState==0){

                    val manager = listView?.layoutManager as LinearLayoutManager
                    listView?.smoothScrollToPosition(manager?.findFirstCompletelyVisibleItemPosition())
//                    manager?.scrollToPositionWithOffset(manager?.findFirstCompletelyVisibleItemPosition(),DensityUtil.dip2px(this@TestAty,10f))
                }
            }
        })
    }

    override fun bindView(): BaseView {
        return this
    }

    override fun createPresenter(): BasePresenter<*, BaseView> {
        return object :BasePresenter<BaseModule,BaseView>(){
            override fun createModule() {

            }
        }
    }

    override val contentId: Int= R.layout.aty_test
}